@tool

static func find_parent_state_chart(node:Node) -> StateChart:
	if node is StateChart:
		return node
	var parent = node.get_parent()
	while parent:
		if parent is StateChart:
			return parent
		parent = parent.get_parent()
	return null
static func events_of(chart:StateChart) -> Array[StringName]:
	var res:Array[StringName] = []
	_collect_events(chart,res)
	res.sort_custom(func (a,b): return a.naturalnocasecmp_to(b) < 0)
	return res
static func _collect_events(node:Node,events:Array[StringName]):
	if node is Transition:
		if node.event != "" and not events.has(node.event):
			events.append(node.event)
	for child in node.get_children():
		_collect_events(child,events)

static func transitions_of(chart:StateChart) -> Array[Transition]:
	var res:Array[Transition] = []
	_collect_transitions(chart,res)
	return res
static func _collect_transitions(node:Node,transitions:Array[Transition]):
	if node is Transition:
		transitions.append(node)
	for child in node.get_children():
		_collect_transitions(child,transitions)
static func get_manager(node:Node) -> StateChartManager:
	var parent = node.get_parent()
	while parent:
		if parent is StateChartManager:
			return parent
		else:
			parent = parent.get_parent()
	return null
static func get_state_names_list(chart:StateChart) -> Array[StringName]:
	var list:Array[StringName] = []
	var queue = []
	queue.push_back(chart)
	while queue.size() > 0:
		var item = queue.pop_front()
		if item is State:
			list.push_back(item.name)
		for child in item.get_children():
			queue.push_back(child)
	return list
